<template>
	<view :class="['search',  {'max-search':!clientRect.width}]" :style="{ 'padding-top':`${clientRect.top}px`}">
		<view class="icon font" @click="handleBack">
			<text class="cuIcon-back"></text>
		</view>
		<view class="inp" :style="{'height':`${clientRect.height}px`,'border-radius':`${clientRect.height/2}px`}">
			<view class="left" @click="handleSearch">
				<text class="cuIcon-search font"></text>
				<text class="btn">ئىزدەش</text>
			</view>
			<view class="right">
				<input class="input" type="text" :value="keyword" @input='keyword_handleInput'
					placeholder="فىلىم ئىزدەش">
			</view>
		</view>
		<view class="blank" :style="{width:`${clientRect.width}px`}"></view>
	</view>
</template>

<script>
	import {
		navigateBack
	} from '@/scripts/compatible/pageOptions.js'
	import {
		height,
		top,
		width,
	} from '@/scripts/compatible/clientRect.js'
	export default {
		props: {
			gradientScale: {
				type: String | Number,
				require: true,
			},
			keyword: {
				type: String,
				require: true,
			},
		},
		data() {
			return {
				clientRect: {
					height: 32,
					top: 12,
					width: 0,
				},
			}
		},
		mounted() {
			this.getWindowByWxMenuBtn()
		},
		methods: {
			handleBack() {
				navigateBack()
			},
			handleSearch() {
				this.$emit('handleSearch')
			},

			keyword_handleInput(e) {
				const keyword = e.detail.value
				this.$emit('setKeyword', keyword)
			},

			getWindowByWxMenuBtn() {
				const clientRect = {
					height,
					top,
					width,
				}
				this.$set(this, 'clientRect', clientRect)
			},
		},
	}
</script>

<style lang="scss" scoped>
	.search {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		z-index: 10;
		height: max-content;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 0 10px 12px;
		width: 100%;
		box-sizing: border-box;

		&.max-search {
			.inp {
				max-width: 200px;
			}
		}

		&.actived {
			.img1 {
				opacity: 0;
			}

			.inp {
				color: #666;
				background-color: #f0f0f0;
				border-color: #f0f0f0;
			}
		}

		.icon {
			width: 32px;
			height: 32px;
			background-color: #f2f2f2;
			display: flex;
			align-items: center;
			justify-content: center;
			border-radius: 50%;
		}

		.font {
			font-size: 16px;
			color: #b9b8b8;
		}

		.inp {
			display: flex;
			justify-content: space-between;
			align-items: center;
			// height: 32px;
			// border-radius: 16px;
			box-sizing: border-box;
			background-color: #f2f2f2;
			padding: 0 10px;
			color: #333;
			font-size: 12px;
			// max-width: 200px;
			flex: 1;
			margin: 0 12px;

			.btn {
				margin: 0 10px 0 5px;
				position: relative;
				bottom: 2px;
			}

			.input {
				flex: 1;
				text-align: right;
				font-size: 12px;
				text-indent: 1em;
			}
		}

		.blank {
			height: 1px;
		}
	}
</style>